package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author likepei
 * @Date 2020/4/4 23:04
 * @Version v1.0
 * @Description 移动端 套餐控制器
 */
@RestController
@RequestMapping("mobile/setmeal")
@Slf4j
public class SetmealController {

    //依赖注入
    @Reference
    private SetmealService setmealService;

    /**
     * 基于套餐Id 获取指定的套餐对象
     * @param id 套餐Id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            //调用Service, 获取指定的套餐对象
            Setmeal setmeal = setmealService.findById(id);
            //返回成功信息
            return new Result(true, MessageConst.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            //返回失败信息
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
    }

    /**
     * 获取所有套餐信息
     * @return
     */
    @RequestMapping("getSetmeal")
    public Result getSetmeal(){
        try {
            //调用Service, 获取所有套餐
            List<Setmeal> setmealList = setmealService.findAll();
            //返回成功信息
            return new Result(true, MessageConst.QUERY_SETMEALLIST_SUCCESS, setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            //返回失败信息
            return new Result(false, MessageConst.QUERY_SETMEALLIST_FAIL);
        }
    }
}

